<!DOCTYPE html>
<!--
Copyright (c) 2019 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/tracing/base/math/earth_movers_distance.html">

<script>
'use strict';

tr.b.unittest.testSuite(function() {
  test('differentBinsNumberHistograms', function() {
    const firstHistogram = [1, 2, 3];
    const secondHistogram = [3, 1, 1, 3];
    assert.throws(() =>
      tr.b.math.earthMoversDistance(firstHistogram, secondHistogram),
    'Histograms have a different number of bins.');
  });

  test('differentSizeHistograms', function() {
    const firstHistogram = [1, 2, 3, 1];
    const secondHistogram = [3, 1, 1, 3];
    assert.throws(() =>
      tr.b.math.earthMoversDistance(firstHistogram, secondHistogram),
    'The histograms\' sizes don\'t match.');
  });

  test('emptyHistograms', function() {
    const firstHistogram = [];
    const secondHistogram = [];
    assert.strictEqual(0,
        tr.b.math.earthMoversDistance(firstHistogram, secondHistogram));
  });

  test('sameHistograms', function() {
    const firstHistogram = [3, 1, 1, 3];
    const secondHistogram = [3, 1, 1, 3];
    assert.strictEqual(0,
        tr.b.math.earthMoversDistance(firstHistogram, secondHistogram));
  });

  test('generalCaseHistograms', function() {
    const firstHistogram = [1, 2, 3, 2];
    const secondHistogram = [3, 1, 1, 3];
    assert.strictEqual(4,
        tr.b.math.earthMoversDistance(firstHistogram, secondHistogram));
  });
});
</script>
